package com.xb.controller;

import com.xb.entity.GetCardIdInfoReqVO;
import com.xb.entity.GetMedicalRecord;
import com.xb.entity.MedicalRecord;
import com.xb.entity.Register;
import com.xb.service.IPatientService;
import com.xb.service.IRegisterService;
import com.xb.service.ITollService;
import com.xb.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * entityController
 * /api/toll
 */
@RestController
@RequestMapping("/api/toll")
public class TollController {
    @Autowired
    private ITollService tollService;
    @Autowired
    private IPatientService patientService;
    @Autowired
    private IRegisterService registerService;

    /**
     * 条件查询
     */
    @GetMapping("/getAllMedicalRecord")
    @RequiresPermissions("system:toll:find")
    public Object getAllMedicalRecord(Register register) {
        return tollService.getAllMedicalRecord(register);
    }

    @PostMapping("/getExaminationToll")
    public Result getExaminationToll(GetCardIdInfoReqVO getCardIdInfoReqVO) {
        return patientService.getExaminationToll(getCardIdInfoReqVO.getCardId());
    }


    @PostMapping("/saveExaminationTollInfo")
    public Result saveExaminationTollInfo(Register register) {
        Result result = new Result();
        register.setChargeStatus(1);
        if (registerService.updateRegister(register) > 0) {
            result.setStatus(Result.RESPONSE_SUCCESS);
        } else {
            result.setStatus(Result.RESPONSE_FAIL);
            result.setMessage("出错了 请联系管理员");
        }
        return result;
    }

    @PostMapping("/getMedicalRecord")
    public Result getMedicalRecord(GetMedicalRecord getMedicalRecord) {
        return tollService.getMedicalRecord(getMedicalRecord);
    }

    @PostMapping("/saveTollInfo")
    public Result saveTollInfo(@RequestBody MedicalRecord medicalRecord, HttpSession session){
        return tollService.saveTollInfo(medicalRecord,session);
    }
}
